package com.mszlu.news.controller;

import com.mszlu.news.service.CommentsService;
import com.mszlu.news.vo.Result;
import com.mszlu.news.vo.params.CommentParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "评论接口")
@RestController
@RequestMapping("comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    ///comments/article/{id}
    @ApiOperation(value = "通过文章id查找文章的评论用户")
    @GetMapping("article/{id}")
    public Result comments(@PathVariable("id") Long id){
        return commentsService.commentsByArticleId(id);
    }

    @ApiOperation(value = "增加评论")
    @PostMapping("create/change")
    public Result comment(@RequestBody CommentParam commentParam){
        return commentsService.comment(commentParam);
    }

    //通过文章id获取文章评论数量
    @ApiOperation(value = "通过文章id获取文章评论数量")
    @PostMapping("count/{articleId}")
    public Result commentsCount(@PathVariable("articleId") Long id){
        return commentsService.commentsCount(id);
    }
}
